package net.dgg.robot.test;

import net.dgg.robot.task.quartz.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class wSmsUtil {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    //测试账号：dlwyx
    //登录密码：wangyx123
    //客户端网站：f.lmobile.cn

    private static String url = "http://api.51welink.com/EncryptionSubmit/SendSms.ashx";
    String accountId="dlsicheng",  password="dgg2020jy";

    public void sendSingle(String phone,String content){
            send(phone,content,"1012818");
    }
    public void sendMuch(String phones,String content){
        send(phones,content,"1012808");
    }
    public void send( String phones,String content,String productId){
        long random = SmsSenderUtil.getRandom();
        long timestamp = SmsSenderUtil.getCurrentTime();

        String accessKey=SmsSenderUtil.calcSendSmsSign(this.accountId, phones.split(",")[0], this.password, random, timestamp);

        Map params = new HashMap();
        params.put("AccountId",this.accountId);
        params.put("ProductId",productId);
        params.put("PhoneNos",phones);
        params.put("Content",content);
        params.put("AccessKey",accessKey);
        params.put("Timestamp",timestamp);
        params.put("Random",random);
        params.put("ExtendNo","");
        params.put("OutId","");
        params.put("SendTime","");
        try {
            String restr = HttpUtil.post(url,params);
            logger.info(restr);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String signName="【顶呱呱】";
        String phones = "18613236735";
//        String phones = "18583360657,17683113396,18613130563,18632439100,18615710409,17602886986,18628979860";
//        String phones = "15208268947,13648003326,18583360657,13693403400,18482151025,17683113396,13880960110,18109025241,13550182384,13547973709,18613130563,18632439100,18615710409,13890700704,18910257190,17380630506,13541367966,17711351006,17778081001,17760522925,18508397458,13550187090,18613236735,18981966583,15388171281,18715897662,18628979860,17502825063,18323612351,18308413816,15608651885,13688477820,13500704005,18382305426,13880576308,18181902837,18349290317,15228623380,18382427871,17602886986,18280081278,15008481695";
        String[] phoneAttr=phones.split(",");
        int len = phoneAttr.length;
        for (int i = 0; i < len; i++) {
            String phone = phoneAttr[i];
            Date date = new Date();
            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
            Random rd = new Random();
            int r = rd.nextInt(100000);

            //验证码
//            String content =signName+ "短信验证码为："+r+",验证码下发时间"+df.format(date);
//            new wSmsUtil().sendSingle(phone,content);


//
//            //通知类
            String cc = signName+"7500万元企业扶持计划，火热进行中。特为您送上4888元专属扶持礼，请收到短信3日内领取，地址：回T退订";
            new wSmsUtil().sendMuch(phone,cc);
        }
    }
}
